﻿using Bomber.TF.GameCenter.BlockCenter;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Bomber.TF.GameCenter.MapCenter
{
    public unsafe abstract class MapBase : GameBase
    {
        protected readonly List<BlockBase> _blockBases;
        public MapBase(int row, int column, int mapWidth, int mapHeight,int cellWidth,int cellHeight, SpeciesType speciesType) : base(speciesType, new Size(mapWidth, mapHeight))
        {
            base.CellHeight = cellHeight;
            base.CellWidth = cellWidth;
            base.MaxColumn = column;
            base.MaxRow = row;
            _blockBases = new List<BlockBase>();
            InitMap();
        }
        public abstract void CreateTool(GameListBase* set);
        
        protected virtual void InitMap()
        {
            for (int i = 0; i < MaxColumn; i++)
            {
                this.AddBlock(new HardBlock(CellWidth, CellHeight), 0, i);
                this.AddBlock(new HardBlock(CellWidth, CellHeight), MaxRow - 1, i);
            }
            for (int i = 0; i < MaxRow; i++)
            {
                this.AddBlock(new HardBlock(CellWidth, CellHeight), i, 0);
                this.AddBlock(new HardBlock(CellWidth, CellHeight), i, MaxColumn - 1);
            }
        }
        public void CreateBlock(GameListBase* set)
        {
            foreach (var block in _blockBases)
            {
                (set + block.Row * MaxColumn + block.Column)->Games.Add(block);
            }
            CreateTool(set);

            _blockBases.Clear();
        }
        protected void AddBlock(BlockBase blockBase, int row, int column)
        {
            blockBase.StartX = base.StartX;
            blockBase.StartY = base.StartY;
            blockBase.MaxColumn = base.MaxColumn;
            blockBase.MaxRow = base.MaxRow;
            blockBase.ZoomX = base.ZoomX;
            blockBase.ZoomY = base.ZoomY;
            blockBase.CellHeight = base.CellHeight;
            blockBase.CellWidth = base.CellWidth;
            blockBase.Row = row;
            blockBase.Column = column;
            blockBase.UpdateLocation();
            _blockBases.Add(blockBase);
        }
        public override void SizeChange(int row, int column, int startX, int startY, int cellWidth, int cellHeight, float zoomX, float zoomY)
        {
            base.SizeChange(row, column, startX, startY, cellWidth, cellHeight, zoomX, zoomY);
        }
    }
}
